import { getCate, getBanner, getSeckill } from "../../utils/api"

const state = {
    cate: [],
    bannercate: [],
    killcate: [],
}

const mutations = {
    changeCate(state, arr) {
        state.cate = arr
    },
    changebannercate(state, arr) {
        state.bannercate = arr
    },
    changekillcate(state, arr) {
        state.killcate = arr
    },
}

const actions = {
    reqchangeCate(context) {
        getCate().then(res => {
            let list = res.data.list.length > 5 ? res.data.list.splice(0, 5) : res.data.list
            // console.log(list);
            context.commit('changeCate', list)
        })
    },
    reqchangebannercate(context) {
        getBanner().then(res => {
            //console.log(res.data.list,88);
            context.commit('changebannercate', res.data.list)
        })
    },
    reqchangekillcate(context) {
        getSeckill().then(res => {
            //console.log(res.data,66);
            context.commit('changekillcate', res.data)
        })
    },
}

const getters = {
    cate(state) {
        return state.cate
    },
    bannercate(state) {
        return state.bannercate
    },
    killcate(state) {
        return state.killcate
    },
}

export default {
    state,
    actions,
    mutations,
    getters,
    namespaced: true
}